<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">疫情监控</block>
		</cu-custom>
		<view class="cu-bar bg-white solid-bottom">
			<view class="action">
				<text class="cuIcon-info text-blue"></text>疫情统计 <text style="margin:15rpx 0 0 20rpx; font-size: 20rpx">更新于 {{ yiQingData.updateTime || '' }}</text>
			</view>
		</view>
		<view class="page_content margin">
			<view class="cu-list grid radius shadow" :class="['col-3','no-border']">
				<view class="cu-item">
					<text style="color:#b03335;">现有确诊</text><br>
					<b style="color:#b03335;font-weight:bold;">{{ yiQingData.totalStoreConfirm  || 0 }}</b><br>
					<text>较昨日 {{ yiQingData.addStoreConfirm >= 0 ? '+':''}}{{ yiQingData.addStoreConfirm || 0 }}</text>
				</view>
				<view class="cu-item">
					<text style="color:#bc6c47;">累计确诊</text><br>
					<b style="color:#bc6c47;font-weight:bold;">{{ yiQingData.totalConfirm || 0 }}</b><br>
					<text>较昨日 {{ yiQingData.addConfirm >= 0 ? '+':'' }}{{ yiQingData.addConfirm || 0 }}</text>
				</view>
				<view class="cu-item">
					<text style="color:#878787;">累计死亡</text><br>
					<b style="color:#878787;font-weight:bold;">{{ yiQingData.totalDead || 0 }}</b><br>
					<text>较昨日 {{ yiQingData.addDead >= 0 ? '+':'' }}{{ yiQingData.addDead || 0 }}</text>
				</view>
				<view class="cu-item">
					<text style="color:#405daa;">境外输入</text>
					<b style="color:#405daa;font-weight:bold;">{{ yiQingData.totalInput || 0 }}</b><br>
					<text>较昨日 {{ yiQingData.addInput >= 0 ? '+':'' }}{{ yiQingData.addInput || 0 }}</text>
				</view>
				<view class="cu-item">
					<text style="color:#583094;">无症状者</text>
					<b style="color:#583094;font-weight:bold;">{{ yiQingData.totalNoSymptom || 0 }}</b><br>
					<text>较昨日 {{ yiQingData.addNoSymptom >= 0 ? '+':'' }}{{ yiQingData.addNoSymptom || 0 }}</text>
				</view>
				<view class="cu-item">
					<text style="color:#3eb53e;">累计治愈</text>
					<b style="color:#3eb53e;font-weight:bold;">{{ yiQingData.totalHeal || 0 }}</b><br>
					<text>较昨日 {{ yiQingData.addHeal >= 0 ? '+':'' }}{{ yiQingData.addHeal || 0 }}</text>
				</view>
			</view>
		</view>
		<view class="cu-bar bg-white solid-bottom">
			<view class="action">
				<text class="cuIcon-info text-blue"></text>风险地区 
				<text style="margin:15rpx 0 0 20rpx; font-size: 20rpx">更新于 {{ currentData.time || '' }}</text>
			</view>
		</view>
		<view class="page_content">
			<view class="cu-list grid radius shadow" :class="['col-3','no-border']">
				<view class="cu-item">
					<text class="text-red">高风险地区 {{ currentData.province || 0 }} 个</text>
				</view>
				<view class="cu-item">
					<text class="text-yellow">中风险地区 {{ currentData.city || 0 }} 个</text>
				</view>
			</view>
		</view>
		<view class="cu-form-group">
			<view class="title">风险省份</view>
			<picker @change="changeCityList" :value="index1" :range="provinceList">
				<view class="picker">
					{{index1?index1:'请选择省份'}}
				</view>
			</picker>
		</view>
		<view class="cu-form-group">
			<view class="title">风险市区</view>
			<picker @change="changeCountyList" :value="index2" :range="cityList">
				<view class="picker">
					{{index2?index2:'请选择市区'}}
				</view>
			</picker>
		</view>
		<view class="cu-form-group">
			<view class="title">风险乡县</view>
			<picker @change="changeAddressList" :value="index3" :range="countyList">
				<view class="picker">
					{{index3?index3:'请选择乡县'}}
				</view>
			</picker>
		</view>
		<view class="padding bg-white">
			<view class="padding" :class="size?'solids':'solid'">
				<view class="padding" v-for="(a,i) in addressList" :key="i">
					<text v-if="a.level==1"> <text class="text-yellow margin-right-xs">【中】</text> {{ a.name }}</text>
					<text v-if="a.level==2"> <text class="text-red margin-right-xs">【高】</text> {{ a.name }}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentDataList: [],
				provinceList: [],
				addressList: [],
				countyList: [],
				index1: '',
				index2: '',
				index3: '',
				cityList: [],
				currentData: {},
				yiQingData: {}
			}
		},
		created() {
			this.getYqAddress()
			this.getYqInfo()
			this.getYqCount()
		},
		methods: {
			getYqInfo() {
				let self = this
				self.$http.get('https://music.tomhub.cn/music/m1/yq/info', {}, {tk: 'e920e52fad7edc74287d6fd7f5e56546'}, {})
					.then(resp => {
						if (resp.code === 200) {
							self.yiQingData = resp.data
						}
					})
			},
			getYqCount() {
				let self = this
				self.$http.get('https://music.tomhub.cn/music/m1/yq/count', {}, {tk: 'e920e52fad7edc74287d6fd7f5e56546'}, {})
					.then(resp => {
						if (resp.code === 200) {
							self.currentData = resp.data
						}
					})
			},
			getYqAddress() {
				let self = this
				self.$http.get('https://music.tomhub.cn/music/m1/yq/address', {}, {tk: 'e920e52fad7edc74287d6fd7f5e56546'}, {})
					.then(resp => {
						if (resp.code === 200) {
							let data = resp.rows
							let list = []
							self.currentDataList = data
							data.forEach(d => {
								if (!list.includes(d.province)) {
									list.push(d.province)
								}
							})
							self.provinceList = list
						}
					})
			},
			changeCityList(val) {
				let self = this
				let list = []
				let data = self.currentDataList
				let info = this.index1 = this.provinceList[val.detail.value]
				this.addressList = []
				data.forEach(d => {
					if (d.province == info) {
						if (!list.includes(d.city)) {
							list.push(d.city)
						}
					}
				})
				self.cityList = list
			},
			changeCountyList(val) {
				let self = this
				let list = []
				let data = self.currentDataList
				let info = this.index2 =  this.cityList[val.detail.value]
				data.forEach(d => {
					if (d.city == info) {
						if (!list.includes(d.county)) {
							list.push(d.county)							
						}
					}
				})
				self.countyList = list
			},
			changeAddressList(val) {
				let self = this
				let data = self.currentDataList
				let info = this.index3 = this.countyList[val.detail.value]
				this.addressList = []
				data.forEach(d => {
					if (d.county == info) {
						let cs = JSON.parse(d.communitys)
						cs.forEach(c => {
							self.addressList.push({name: c, level: d.level})
						})
					}
				})
			},
			es6duplicate(arr,type){
				if(arr.length == 0){
					return arr;
				}else{
					if(type){
						let obj = {}
						let newArr = arr.reduce((cur,next) => {
							obj[next.label] ? "" : obj[next.label] = true && cur.push(next);
							return cur;
						},[])
						return newArr;
					}else{
						return Array.from(new Set(arr));
					}
				}
			},
		}
	}
</script>

<style>

</style>